<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>focushandler.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_events_focushandler.js.html">focushandler.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview This event handler allows you to catch focusin and focusout
<a name="line17"></a> * events on  descendants. Unlike the &quot;focus&quot; and &quot;blur&quot; events which do not
<a name="line18"></a> * propagate consistently, and therefore must be added to the element that is
<a name="line19"></a> * focused, this allows you to attach one listener to an ancester and you will
<a name="line20"></a> * be notified when the focus state changes of ony of its descendants.
<a name="line21"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line22"></a> * @see ../demos/focushandler.html
<a name="line23"></a> */
<a name="line24"></a>
<a name="line25"></a>goog.provide(&#39;goog.events.FocusHandler&#39;);
<a name="line26"></a>goog.provide(&#39;goog.events.FocusHandler.EventType&#39;);
<a name="line27"></a>
<a name="line28"></a>goog.require(&#39;goog.events&#39;);
<a name="line29"></a>goog.require(&#39;goog.events.BrowserEvent&#39;);
<a name="line30"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line31"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * This event handler allows you to catch focus events when descendants gain or
<a name="line37"></a> * loses focus.
<a name="line38"></a> * @param {Element|Document} element  The node to listen on.
<a name="line39"></a> * @constructor
<a name="line40"></a> * @extends {goog.events.EventTarget}
<a name="line41"></a> */
<a name="line42"></a>goog.events.FocusHandler = function(element) {
<a name="line43"></a>  goog.events.EventTarget.call(this);
<a name="line44"></a>
<a name="line45"></a>  /**
<a name="line46"></a>   * This is the element that we will listen to the real focus events on.
<a name="line47"></a>   * @type {Element|Document}
<a name="line48"></a>   * @private
<a name="line49"></a>   */
<a name="line50"></a>  this.element_ = element;
<a name="line51"></a>
<a name="line52"></a>  // In IE we use focusin/focusout and in other browsers we use a capturing
<a name="line53"></a>  // listner for focus/blur
<a name="line54"></a>  var typeIn = goog.userAgent.IE ? &#39;focusin&#39; : &#39;focus&#39;;
<a name="line55"></a>  var typeOut = goog.userAgent.IE ? &#39;focusout&#39; : &#39;blur&#39;;
<a name="line56"></a>
<a name="line57"></a>  /**
<a name="line58"></a>   * Store the listen key so it easier to unlisten in dispose.
<a name="line59"></a>   * @private
<a name="line60"></a>   * @type {goog.events.Key}
<a name="line61"></a>   */
<a name="line62"></a>  this.listenKeyIn_ =
<a name="line63"></a>      goog.events.listen(this.element_, typeIn, this, !goog.userAgent.IE);
<a name="line64"></a>
<a name="line65"></a>  /**
<a name="line66"></a>   * Store the listen key so it easier to unlisten in dispose.
<a name="line67"></a>   * @private
<a name="line68"></a>   * @type {goog.events.Key}
<a name="line69"></a>   */
<a name="line70"></a>  this.listenKeyOut_ =
<a name="line71"></a>      goog.events.listen(this.element_, typeOut, this, !goog.userAgent.IE);
<a name="line72"></a>};
<a name="line73"></a>goog.inherits(goog.events.FocusHandler, goog.events.EventTarget);
<a name="line74"></a>
<a name="line75"></a>
<a name="line76"></a>/**
<a name="line77"></a> * Enum type for the events fired by the focus handler
<a name="line78"></a> * @enum {string}
<a name="line79"></a> */
<a name="line80"></a>goog.events.FocusHandler.EventType = {
<a name="line81"></a>  FOCUSIN: &#39;focusin&#39;,
<a name="line82"></a>  FOCUSOUT: &#39;focusout&#39;
<a name="line83"></a>};
<a name="line84"></a>
<a name="line85"></a>
<a name="line86"></a>/**
<a name="line87"></a> * This handles the underlying events and dispatches a new event.
<a name="line88"></a> * @param {goog.events.BrowserEvent} e  The underlying browser event.
<a name="line89"></a> */
<a name="line90"></a>goog.events.FocusHandler.prototype.handleEvent = function(e) {
<a name="line91"></a>  var be = e.getBrowserEvent();
<a name="line92"></a>  var event = new goog.events.BrowserEvent(be);
<a name="line93"></a>  event.type = e.type == &#39;focusin&#39; || e.type == &#39;focus&#39; ?
<a name="line94"></a>      goog.events.FocusHandler.EventType.FOCUSIN :
<a name="line95"></a>      goog.events.FocusHandler.EventType.FOCUSOUT;
<a name="line96"></a>  this.dispatchEvent(event);
<a name="line97"></a>};
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>/** @override */
<a name="line101"></a>goog.events.FocusHandler.prototype.disposeInternal = function() {
<a name="line102"></a>  goog.events.FocusHandler.superClass_.disposeInternal.call(this);
<a name="line103"></a>  goog.events.unlistenByKey(this.listenKeyIn_);
<a name="line104"></a>  goog.events.unlistenByKey(this.listenKeyOut_);
<a name="line105"></a>  delete this.element_;
<a name="line106"></a>};
</pre>


</body>
</html>
